import backtrader as bt
import pandas as pd
import datetime
from utils.turn2100 import trans


cerebro = bt.Cerebro()

def origin_data(currency):
    dataframe = pd.read_csv("data/%s/data.csv" % currency)
    dataframe = trans(dataframe)
    dataframe['open_time'] = pd.to_datetime(dataframe['open_time'])
    dataframe.set_index('open_time', inplace=True)
    dataframe['openinterest'] = 0
    data0 = bt.feeds.PandasData(
        dataname=dataframe,
        fromdate=datetime.datetime(2019, 10, 15),
        todate=datetime.datetime(2020, 11, 9)
    )
    data0.plotinfo.plotname = currency
    cerebro.adddata(data0, name=currency)
    return data0

def add_data(data0, currency):
    dataframe = pd.read_csv("data/%s/data.csv" % currency)
    dataframe = trans(dataframe)
    dataframe['open_time'] = pd.to_datetime(dataframe['open_time'])
    dataframe.set_index('open_time', inplace=True)
    dataframe['openinterest'] = 0
    data_ = bt.feeds.PandasData(
        dataname=dataframe,
        fromdate=datetime.datetime(2019, 10, 15),
        todate=datetime.datetime(2020, 11, 9)
    )
    data_.plotinfo.plotname = currency
    data_.plotinfo.plotmaster = data0
    cerebro.adddata(data_, name=currency)
    return cerebro

data0 = origin_data("BNBUSDT")
add_data(data0, "DJI")
add_data(data0, "HTUSDT")
add_data(data0, "SHA")
cerebro = add_data(data0, "LEOUSDT")
